<template>
	<view class="container-wrapper">
		<view class="banner-wrapper row-center">
			<u--image :showLoading="true" src="/static/banner.png" width="594rpx" height="394rpx"></u--image>
			<view class="title">校园交通违章管理系统</view>
		</view>
		<view class="content-wrapper">
			<u--form errorType="toast" labelPosition="left" labelWidth="120rpx" :model="formModel" :rules="rules"
				ref="uForm">
				<u-form-item label="用户名" prop="username" borderBottom>
					<u--input v-model="formModel.username" placeholder="请输入用户名" border="none"></u--input>
				</u-form-item>
				<u-form-item label="密码" prop="password" borderBottom>
					<u--input type="password" v-model="formModel.password" placeholder="请输入密码" border="none"></u--input>
				</u-form-item>
			</u--form>
			<u-button class="custom-style mt16" text="登 录" @click="onLogin"></u-button>
		</view>
		<uniLoading v-if="loadingCover" bgColor="#fff"></uniLoading>
	</view>
</template>

<script>
	import {
		onLoginApi
	} from '@/apis/login.js'
	export default {
		data() {
			return {
				loadingCover: true,
				formModel: {
					username: '',
					password: '',
					openid: '',
					// openid: 'oP5QP63b4uxi6LwuphasFW1RIuJY'
				},

				rules: {
					'username': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'password': {
						type: 'string',
						required: true,
						message: '请填写密码',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad(options) {
			this.formModel.openid = options.openid;
			setTimeout(() => {
				this.loadingCover = false;
			}, 500)
		},
		methods: {
			async onLogin() {
				uni.showLoading({
					title: '登录中',
					mask: true,
				})
				try {
					let resp = await onLoginApi(this.formModel);
					let token = resp.token;
					uni.setStorageSync('token', token)
					this.$commonUtil.redirectTo('/pages/index/index')
				} catch (e) {
					console.log(`%登录-${e.message},background:orange`)
				} finally {
					uni.hideLoading()
				}

			}
		}
	}
</script>

<style scoped lang="scss">
	.container-wrapper {
		width: 100%;
		min-height: 100%;
		background: #fff;
		padding-top: 50rpx;

		.banner-wrapper {
			width: 100%;
			position: relative;

			.title {
				position: absolute;
				font-weight: 500;
				font-size: 38rpx;
				color: #333333;
				top: 20rpx;
			}
		}

		.content-wrapper {
			margin-top: 42rpx;
			padding: 0 50rpx;

			.custom-style {
				background-color: #3B67A5;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				border-radius: 15rpx;
				margin-top: 80rpx;
			}
		}


	}
</style>